/**
 * \file defines.h
 * \brief Common definitions
 * \author Radim Badsi <radim.badsi@polytech.univ-montp2.fr>
 * \date 24/06/2009
 */

#ifndef DEFINES_H
#define DEFINES_H

/* Configuration */

/**
  * \def FREQUENCY 
  * uC operating frequency
  */
#define FREQUENCY 20000000 /* Hz */

/**
  * \def TIMER0_INIT
  * Scheduler clock timer initial value
  */
#define TIMER0_INIT 65536-(0.001*(FREQUENCY/32)) /* 1 ms */

/* Ports */
/**
  * \def CAN_TX_TRIS
  * CAN TX signal direction
  */
#define CAN_TX_TRIS TRISBbits.TRISB2

/**
  * \def CAN_RX_TRIS
  * CAN RX signal direction
  */
#define CAN_RX_TRIS TRISBbits.TRISB3 

/**
  * \def LED0_TRIS
  * LED0 signal direction
  */
#define LED0_TRIS TRISAbits.TRISA2

/**
  * \def LED1_TRIS
  * LED1 signal direction
  */
#define LED1_TRIS TRISAbits.TRISA3

/**
  * \def LED0
  * LED 0
  */
#define LED0 PORTAbits.RA2

/**
  * \def LED1
  * LED 1
  */
#define LED1 PORTAbits.RA3

//#define SW0_TRIS TRISAbits.TRISA0
//#define SW1_TRIS TRISAbits.TRISA1
//#define SW0 PORTAbits.RA0
//#define SW1 PORTAbits.RA1

/**
  * \def MCP2551_RS_TRIS
  * MCP2551_RS signal direction
  */
#define MCP2551_RS_TRIS TRISDbits.TRISD1

/** 
  * \def MCP2551_RS
  * MCP2551's Rs pin
  * MCP_2551_RS = 1 -> SLEEP mode
  * MCP_2551_RS = 0 -> Normal mode
  */
#define MCP2551_RS	PORTDbits.RD1

/**
  * \def USART_RX_TRIS
  * USART RX signal direction
  */
#define USART_RX_TRIS TRISCbits.TRISC7

/**
  * \def USART_TX_TRIS
  * USART TX signal direction
  */
#define USART_TX_TRIS TRISCbits.TRISC6

/**
  * \def CONTROL_IN_RTC
  * RTC I2C address (input)
  */
#define CONTROL_IN_RTC 0xA2

/**
  * \def CONTROL_OUT_RTC
  * RTC I2C address (output)
  */
#define CONTROL_OUT_RTC 0xA3

/**
  * \def tmr_reset()
  * Reset the OS clock
  */
#define tmr_reset() WriteTimer0(TIMER0_INIT);

/**
  * \def clr_watchdog()
  * Reset the watchdog
  */
#define clr_watchdog() _asm CLRWDT _endasm

/**
  * \enum _ERROR_CODE
  * Error code
  */
typedef enum _ERROR_CODE { OK = 0, WARNING = -1, ERROR = -2, FATAL = -3 } ERROR_CODE;

/**
  * \enum _MODE
  * Operating mode of the satellite
  */
typedef enum _MODE { PRELAUNCH = 0x0,
					 ANT_DEPLOYMENT = 0x3,
					 SAFE = 0xF,
					 MISSION = 0x3F
				  } MODE;					
#endif